using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class SupportsDAO
	{
		public SupportsDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Supports> GetSupportss()
		{
			try
			{
				List<Supports> lstSupportss = new List<Supports>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTSupportss",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Supports oSupports = new Supports();
					oSupports.ID = Convert.ToInt32(oDbDataReader["ID"]);
                    oSupports.RowNum = Convert.ToInt32(oDbDataReader["RowNum"]);


					if(oDbDataReader["Yahoo"] != DBNull.Value)
						oSupports.Yahoo = Convert.ToString(oDbDataReader["Yahoo"]);

					if(oDbDataReader["Fullname"] != DBNull.Value)
						oSupports.Fullname = Convert.ToString(oDbDataReader["Fullname"]);
					lstSupportss.Add(oSupports);
				}
				oDbDataReader.Close();
				return lstSupportss;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Supports GetSupports(int ID)
		{
			try
			{
				Supports oSupports = new Supports();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTSupports",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oSupports.ID = Convert.ToInt32(oDbDataReader["ID"]);

					if(oDbDataReader["Yahoo"] != DBNull.Value)
						oSupports.Yahoo = Convert.ToString(oDbDataReader["Yahoo"]);

					if(oDbDataReader["Fullname"] != DBNull.Value)
						oSupports.Fullname = Convert.ToString(oDbDataReader["Fullname"]);
				}
				oDbDataReader.Close();
				return oSupports;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddSupports(Supports oSupports)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTSupports",CommandType.StoredProcedure);
				if (oSupports.Yahoo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Yahoo",DbType.String,oSupports.Yahoo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Yahoo",DbType.String,DBNull.Value));
				if (oSupports.Fullname!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fullname",DbType.String,oSupports.Fullname));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fullname",DbType.String,DBNull.Value));

				return Convert.ToInt32(DbProviderHelper.ExecuteScalar(oDbCommand));
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateSupports(Supports oSupports)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATESupports",CommandType.StoredProcedure);
				if (oSupports.Yahoo!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Yahoo",DbType.String,oSupports.Yahoo));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Yahoo",DbType.String,DBNull.Value));
				if (oSupports.Fullname!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fullname",DbType.String,oSupports.Fullname));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fullname",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,oSupports.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSupports(Supports oSupports)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETESupports",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,oSupports.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSupports(int ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETESupports",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.Int32,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
